﻿@model Topic
@{
	ViewBag.Title = Model.Title;
	ViewBag.HasPostAccess = Model.HasPostAccess(Role);
}
@section Head{
	@Html.MetaDescription(Utils.Summarize(Utils.RemoveTags(Model.Description), 160, ""))
}
<ul class="path">
    <li class="first">@ActionLinkLocalized("Main", "Index", "Home")</li>
	<li>@ActionLinkLocalized("Forums", "List", "Forums")</li>
	<li>@Html.ActionLink(Model.Forum.Name, "Detail", "Forums", new{forum=Model.Forum.ShortName, page=1}, null)</li>
</ul>
<div class="topicDetail">
	<h1>@ViewBag.Title</h1>
	<div class="options">
		<a rel="nofollow" href="@Url.Action("LatestMessages")">@Html.Img("~/images/iconrss.gif", "rss")</a>
	</div>
	<p class="info">
		@T("Posted by") <strong class="userName">@Html.ActionLink(Model.User.UserName, "Detail", "Users", new{id=Model.User.Id}, new{rel="nofollow"})</strong>
		-
		@Html.Date(Model.Date)
	</p>
	<div class="description">
		@Html.Raw(Model.Description)
	</div>
    @{
        var messages = Model.Messages;
    }
    @Html.Pager(Config.UI.MessagesPerPage, PageIndex, (int)ViewBag.TotalMessages, Config.UI.PagesNearCurrent, S("Previous"), S("Next"))
	@if (messages.Count > 0)
	{
		<ul id="messages">
		@foreach (Message m in messages)
		{
			Html.RenderPartial("MessageItem", m);
		}
		</ul>
	}
    @if ((int)ViewBag.TotalMessages > 0)
	{
		<div class="pagerSummary">
			@T("Displaying <span class=\"firstItem\">{0}</span> to <span class=\"lastItem\">{1}</span> of <span class=\"totalItems\">{2}</span> messages",
				(this.PageIndex - 1) * Config.UI.MessagesPerPage + 1,
				(this.PageIndex -1) * Config.UI.MessagesPerPage + messages.Count,
                (int)ViewBag.TotalMessages)
		</div>
	}
	@*<div id="pagerClient" style="display:none;"><a href="#" onclick="pager.more();return false;">@Html.Img("~/images/loadingMini.gif", "") @T("Show more messages")</a></div>*@
    @Html.Pager(Config.UI.MessagesPerPage, PageIndex, (int)ViewBag.TotalMessages, Config.UI.PagesNearCurrent, S("Previous"), S("Next"))
	@Html.Partial("Toolbar")
	@Html.Partial("Related")
</div>
@Html.Script("~/scripts/overtip.js")
@*@Html.Script("~/scripts/pager.js")*@
@Html.Script("~/scripts/quoting.js")
<script type="text/javascript">
    $(document).ready(function () {
		quoting.init();
		//pager.init('@Url.Action("PageMore", "Topics", new{id=Model.Id})', '@Url.Action("PageUntil", "Topics", new{id=Model.Id})', '@T("The browser has lost session, click ok to return to the login page")');
		$(document).trigger("dataLoaded");
    });
</script>
<script type="text/javascript">
	$(document).ready(function ()
	{
		$("#messages li")
			.live("tap", function () { $(this).toggleClass("over"); })
			.live("mouseenter", function () { $(this).css("background-color","").addClass("over"); })
			.live("mouseleave", function () { $(this).removeClass("over"); });
	});
    function flagMessage(mid, url)
    {
        $.post(url, { mid: mid }, function (data)
        {
	        alert('@T("Thanks you, a moderator will review the message.")');
	    });
		return false;
	}
	function deleteMessage(mid, url)
	{
		return deleteMessageCommon(mid, url, '@T("Are you sure you want to hide the message #{0}?")', '@T("Message removed")', null);
    }
</script>